/**
 *    title:  network.h
 *    author:  sleeeeeping
 *    created:  2024-08-16 09:13:38
**/
#ifndef _NETWORK_H__
#define _NETWORK_H__

#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

typedef struct NetWork {
    int type;
    int sockfd;
    socklen_t addrlen;
    struct sockaddr_in addr;
    bool isServer;
} NetWork;

/**
 * 1、创建结构NetWork对象
 * 2、创建socket对象
 * 3、准备通信地址
 * 4、根据type、isServer决定执行哪个流程
 *      tcp server: bind、listen
 *      tcp client: connect
 *      udp server: bind
 *      udp client: 无
 * 5、返回NetWork对象
*/
NetWork *createNetWork(int , const char *, unsigned short , bool);

NetWork *acceptNetWork(NetWork *);

int sendNetWork(NetWork *, const void *, size_t );

int recvNetWork(NetWork *, void *, size_t );

int closeNetWork(NetWork *);

#endif // _NETWORK_H__